<?php namespace system\middleware;

use houdunwang\middleware\build\Middleware;

use system\model\Config as ConfigMode;

class Config implements Middleware{
	//执行中间件
	public function run($next) {
//         echo "中间件执行了";
//        获取系统配置
         $this->setSysConfig();
//        获取微信配置
         $this->setWechatConfig();
//        获取微信消息
         $this->setWechatMessage();
         $next();
	}
//	获取系统配置项
	public function setSysConfig( ){
        $model = configMode::find( 1 );
        $field = $model ? json_decode( $model[ 'system' ] , true ) : [];
        //p($field);
        //系统v函数，需要看函数，追踪代码
        v( 'config' , $field );
    }
    public function setWechatConfig( ){
        $model = configMode::find( 1 );
        $field = $model ? json_decode( $model[ 'weixin' ] , true ) : [];
        //p($field);
        
//       设置到配置项
        \houdunwang\config\Config::set('wechat',$field);
    }
    
    public function setWechatMessage( ){
        $model = configMode::find( 1 );
        $field = $model ? json_decode( $model[ 'wechat_message' ] , true ) : [];
        //p($field);

//       设置到配置项
        \houdunwang\config\Config::set('wechat_message',$field);
    }
}